import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart';
import 'package:laos_mall/app_route.dart';
import 'package:laos_mall/common/style/extension_util.dart';
import 'package:laos_mall/common/widght/custom_tab_indicator.dart';
import 'package:laos_mall/translations/lo_la.dart';
import 'package:skeletonizer/skeletonizer.dart';
import 'common/style/app_style.dart';
import 'translations/en_US.dart';
import 'translations/zh_cn.dart';

void main() async{
  // WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
  await ScreenUtil.ensureScreenSize();
  // SystemChrome.setSystemUIOverlayStyle(
  //     const SystemUiOverlayStyle(statusBarColor: Colors.transparent));
  await GetStorage.init();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {

    return GetMaterialApp(
      title: 'laos mall',
      // theme: ThemeData(
      //   colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
      //   useMaterial3: true,
      // ),
      theme: AppTheme.norTheme,
      debugShowCheckedModeBanner: false,
      // locale: Get.deviceLocale,
      supportedLocales: [
        Locale('en', 'US'),  // 英语
        Locale('lo', 'LA'),  // 老挝语
      ],
      locale: const Locale('en', 'US'),
      translations: MyTranslations(),
      fallbackLocale: const Locale('en','US'),
      builder: (context,child){
        ScreenUtil.init(context,designSize: const Size(375, 812));
        SmartDialog.config
          ..custom = SmartConfigCustom(
            maskColor: Colors.black.withOpacity(0.35),
            useAnimation: true,
          )
          ..attach = SmartConfigAttach(
            animationType: SmartAnimationType.scale,
            usePenetrate: false,
          )
          ..loading = SmartConfigLoading(
            clickMaskDismiss: false,
            leastLoadingTime: const Duration(milliseconds: 0),
          )
          ..toast = SmartConfigToast(
            intervalTime: const Duration(milliseconds: 100),
            displayTime: const Duration(milliseconds: 2000),
            alignment: Alignment.center
          );
        FlutterSmartDialog.init();

        return GestureDetector(
            onTap: () {
              FocusScopeNode currentFocus = FocusScope.of(context);
              if (!currentFocus.hasPrimaryFocus &&
                  currentFocus.focusedChild != null) {
                FocusManager.instance.primaryFocus?.unfocus();
              }
            },child:
        FlutterSmartDialog(
          child: child,
        ));
      },
      // home: MainPage(),
      getPages: AppRouter.getPages,
      initialRoute: AppRouter.main,
    );
  }
}


class MyTranslations extends Translations {
  @override
  Map<String, Map<String, String>> get keys => {
    'en_US': EnUs.values,
    'zh_CN': ZhCn.values,
    'lo_LA':LOLA.values
  };
}

class AppTheme {
  ///默认下的主题
  static final ThemeData norTheme = ThemeData(
    brightness: Brightness.light,
    appBarTheme: AppBarTheme(
        iconTheme: IconThemeData(color: AppColor.textColor,size: 16),
        systemOverlayStyle: const SystemUiOverlayStyle(
            statusBarColor: Colors.transparent,
            statusBarBrightness: Brightness.light,
            statusBarIconBrightness: Brightness.dark,
            systemNavigationBarColor: Colors.white
        ),
        elevation: 0,
        centerTitle: false,
        backgroundColor: AppColor.backGroundColor,
        titleTextStyle:  TextStyle(
            fontSize: 12, fontWeight: FontWeight.bold, color: AppColor.textColor),
        scrolledUnderElevation: 0,


    ),

    colorScheme: ColorScheme.light(
        background: AppColor.backGroundColor, primary: AppColor.primaryColor),
    primaryColor: AppColor.primaryColor,
    primaryColorLight: AppColor.primaryColor,
    primaryColorDark: AppColor.primaryColor,
    tabBarTheme: TabBarTheme(indicatorColor:
        AppColor.primaryColor,
      indicatorSize: TabBarIndicatorSize.label,
      labelColor: "#111111".toColor,
    ),
    bottomNavigationBarTheme: const BottomNavigationBarThemeData(
      backgroundColor: Colors.black,
      showUnselectedLabels: false, // 不显示未选中的文字
      showSelectedLabels: false,
    ),
    scaffoldBackgroundColor: AppColor.white,
    useMaterial3: false,
    extensions:[
      SkeletonizerConfigData(textBorderRadius: TextBoneBorderRadius.fromHeightFactor(1))
    ]
  );
}